﻿
(function (globals) {
    if (Array.prototype.find) return;

    var find = function (predicate) {
        var list = Object(this);
        var length = list.length < 0 ? 0 : list.length >>> 0; // ES.ToUint32;
        if (length === 0) return undefined;
        if (typeof predicate !== 'function' || Object.prototype.toString.call(predicate) !== '[object Function]') {
            throw new TypeError('Array#find: predicate must be a function');
        }
        var thisArg = arguments[1];
        var data = []

        for (var i = 0, value; i < length; i++) {
            value = list[i];
            if (predicate.call(thisArg, value, i, list)) 
                data.push(value)
        }
        return data;
    };

    if (Object.defineProperty) {
        try {
            Object.defineProperty(Array.prototype, 'find', {
                value: find, configurable: true, enumerable: false, writable: true
            });
        } catch (e) { }
    }

    if (!Array.prototype.find) {
        Array.prototype.find = find;
    }
})(this);
